package cn.com.duiba.millionaire.center.biz.dao.impl;

import cn.com.duiba.millionaire.center.api.requestParam.MillionaireQuestionBagRequestParam;
import cn.com.duiba.millionaire.center.biz.constants.DatabaseSchema;
import cn.com.duiba.millionaire.center.biz.dao.BaseDao;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireQuestionBagDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireQuestionBagEntity;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by sty on 1/18/18.
 */
@Repository
public class MillionaireQuestionBagDaoImpl extends BaseDao implements MillionaireQuestionBagDao {
    @Override
    public MillionaireQuestionBagEntity insert(MillionaireQuestionBagEntity millionaireQuestionBagEntity) {
        insert("insert", millionaireQuestionBagEntity);
        return millionaireQuestionBagEntity;
    }

    @Override
    public int updateById(MillionaireQuestionBagEntity millionaireQuestionBagEntity) {
        return update("updateById", millionaireQuestionBagEntity);
    }

    @Override
    public MillionaireQuestionBagEntity findById(Long id) {
        return selectOne("findById", id);
    }

    @Override
    public int findByPageCount(MillionaireQuestionBagRequestParam param) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("bagType",param.getBagType());
        return selectOne("findByPageCount",params);
    }

    @Override
    public List<MillionaireQuestionBagEntity> findByPage(MillionaireQuestionBagRequestParam param) {
        Map<String, Object> params = Maps.newHashMap();
        Integer pageSize = param.getPageSize();
        params.put("startIndex", (param.getPageNum() - 1) * pageSize);
        params.put("pageSize", pageSize);
        params.put("bagType",param.getBagType());
        return selectList("findByPage",params);
    }

    @Override
    public int deleteById(Long id) {
        return update("deleteById", id);
    }

    @Override
    public int changeQuestionNum(Long id, int num) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("id", id);
        params.put("num", num);
        return update("changeQuestionNum", params);
    }

    @Override
    protected DatabaseSchema chooseSchema() {
        return DatabaseSchema.MILLIONAIRE_CONFIG;
    }
}
